package com.example.locationgps;

import android.provider.CalendarContract;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;


public class LoginActivity {

    public Connection conectDB(){
        Connection connection = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@58.34.215.18:1003/orcl", "LSN",
                    "LSN");
            System.out.println("数据库连接成功");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("加载程序驱动出错");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return connection;
    }

    //public void dataToDB(String realtime, double lon, double lat, double mlon, double mlat, double height, double acc,Long ltime,String sxtid){
    public void dataToDB(Connection connection , GPSInfor gpsInfor){
        try {
            String insertStr = "INSERT INTO LNGANDLAT(id,REALTIME,LONGITUDE,LATITUDE,MLON,MLAT,LTIME,CMNUM,SYSTIME,EQUITYPE,ALINETIME,DIRECTION,SPEED) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement pstmt = connection.prepareStatement(insertStr);
            pstmt.setString(1,gpsInfor.getId());
            pstmt.setString(2,gpsInfor.getRealtime());
            pstmt.setDouble(3,gpsInfor.getLon());
            pstmt.setDouble(4,gpsInfor.getLat());
            pstmt.setDouble(5,gpsInfor.getMlon());
            pstmt.setDouble(6,gpsInfor.getMlat());
            pstmt.setLong(7,gpsInfor.getLtime());
            pstmt.setString(8,gpsInfor.getSxtid());
            pstmt.setString(9,gpsInfor.getSysdate());
            pstmt.setInt(10,gpsInfor.getEquitype());
            pstmt.setLong(11,gpsInfor.getAlinetime());
            pstmt.setDouble(12,gpsInfor.getDirection());
            pstmt.setDouble(13,gpsInfor.getSpeed());
            pstmt.executeUpdate();
            System.out.println("插入数据库成功");
            pstmt.close();
        }catch (SQLException throwables){
            throwables.printStackTrace();
        }
    }
}
